package com.hee.erp.modules.controller;


import com.hee.erp.common.R;
import com.hee.erp.modules.entity.SysCompany;
import com.hee.erp.modules.entity.SysDepart;
import com.hee.erp.modules.service.ISysCompanyService;
import com.hee.erp.modules.service.ISysDepartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weizehong
 * @since 2022-04-15
 */
@RestController
@Api(tags = "SysDepartController")
@RequestMapping("/modules/sysDepart")
public class SysDepartController {

    @Autowired
    ISysDepartService departService;

    @GetMapping("/getAllList")
    @ApiOperation("getAllList")
    public R getAllList(){
        List<SysDepart> list = departService.list();
        return R.success(list);
    }

    @PostMapping("/save")
    @ApiOperation("save")
    public R<String> save(@RequestBody SysDepart entity) {
        if (StringUtils.isBlank(entity.getId())) {
            departService.save(entity);
        } else {
            departService.updateById(entity);
        }
        return R.success(entity.getId());
    }

    @GetMapping("/delById")
    @ApiOperation("delById")
    public R<Boolean> delById(String id) {
        departService.removeById(id);
        return R.success(true);
    }

    @GetMapping("/getListByCompanyId")
    @ApiOperation("getListByCompanyId")
    public R getListByCompanyId(String companyId){
        List<SysDepart> list = departService.getListByCompanyId(companyId);
        return R.success(list);
    }
}

